﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Open.Core.Extension;
using Open.Core.Extension.Results;
using Open.Product.Domain.Dto;
using Open.Product.Domain.Service;
using Swashbuckle.AspNetCore.Annotations;
using System.Net;

namespace Product.API.Controllers
{
    [Route("api/v1/[controller]")]
    [Authorize]
    [ApiController]
    [SwaggerTag("商品服务")]
    public class ProductController : OpenApiController
    {
        private readonly IProductService _productAppService;
        public ProductController(IProductService _productAppService)
        {
            this._productAppService = _productAppService;
        }

        /// <summary>
        /// 分页获取商品信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost, Route("list")]
        [ProducesResponseType(typeof(Open.Product.Domain.Model.Product), (int)HttpStatusCode.OK)]
        public async Task<PageResultDto<Open.Product.Domain.Model.Product>> GetListAsync(ProductGetListInput input)
        {
            return await this._productAppService.GetListAsync(input);
        }

        /// <summary>
        /// 筛选获取商品信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost, Route("query")]
        public async Task<IActionResult> GetQueryAsync(ProductRequestInput input)
        {
            var data = await this._productAppService.GetQueryAsync(input);
            return data.Code == StateCode.Ok ? Success(data.Data) : Fail(data.Message);
        }
    }
}
